<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="8">
			<p-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'createBy', validatorRules.createBy]" placeholder="请输入创建人"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择创建日期" v-decorator="[ 'createTime', validatorRules.createTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'updateBy', validatorRules.updateBy]" placeholder="请输入更新人"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择更新日期" v-decorator="[ 'updateTime', validatorRules.updateTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="时间戳" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择时间戳" v-decorator="[ 'timestamp', validatorRules.timestamp]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="公司标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'companyId', validatorRules.companyId]" placeholder="请输入公司标识"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工厂标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'factoryId', validatorRules.factoryId]" placeholder="请输入工厂标识"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="租户标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'clientId', validatorRules.clientId]" placeholder="请输入租户标识"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="替换人员标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'substituteId', validatorRules.substituteId]" placeholder="请输入替换人员标识"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="数据软删除标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'flag', validatorRules.flag]" placeholder="请输入数据软删除标识" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="抽样样本" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sample', validatorRules.sample]" placeholder="请输入抽样样本"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料内码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mid', validatorRules.mid]" placeholder="请输入物料内码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mcode', validatorRules.mcode]" placeholder="请输入物料编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入物料名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sprc', validatorRules.sprc]" placeholder="请输入规格型号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料小类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'subcategory', validatorRules.subcategory]" placeholder="请输入物料小类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料大类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mcategory', validatorRules.mcategory]" placeholder="请输入物料大类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="检验结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inspectResult', validatorRules.inspectResult]" placeholder="请输入检验结果"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="图片url" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'photoUrl', validatorRules.photoUrl]" placeholder="请输入图片url"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inspectBillno', validatorRules.inspectBillno]" placeholder="请输入送检单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="基本信息id" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'basicInfoId', validatorRules.basicInfoId]" placeholder="请输入基本信息id"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: "MesQcIncomeCheckProjectModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDate,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        createBy: {},
        createTime: {},
        updateBy: {},
        updateTime: {},
        remark: {},
        timestamp: {},
        companyId: {},
        factoryId: {},
        clientId: {},
        substituteId: {},
        flag: {},
        sample: {},
        mid: {},
        mcode: {},
        mname: {},
        sprc: {},
        subcategory: {},
        mcategory: {},
        inspectResult: {},
        photoUrl: {},
        inspectBillno: {},
        basicInfoId: {},
        mexplain: {},
        },
        url: {
          add: '/mes-quality/mesQcIncomeBasicInfo/addMesQcIncomeCheckProject',
          edit: '/mes-quality/mesQcIncomeBasicInfo/editMesQcIncomeCheckProject',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','sample','mid','mcode','mname','sprc','subcategory','mcategory','inspectResult','photoUrl','inspectBillno','basicInfoId','mexplain'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['basicInfoId'] = this.mainId
                  this.formData['basicInfoId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','sample','mid','mcode','mname','sprc','subcategory','mcategory','inspectResult','photoUrl','inspectBillno','basicInfoId','mexplain'))
      },


    }
  }
</script>
